package com.abc.robot01.rn

import android.content.Intent
import android.os.Bundle
import androidx.lifecycle.lifecycleScope
import com.abc.robot01.activity.BaseActivity
import com.abc.robot01.activity.RenderActivity
import com.abc.robot01.activity.startActivity
import com.abc.robot01.retrofit.RetrofitService
import com.abc.robot01.vivemodel.Robot
import com.facebook.react.ReactActivity
import com.facebook.react.ReactActivityDelegate
import com.facebook.react.defaults.DefaultNewArchitectureEntryPoint.fabricEnabled
import com.facebook.react.defaults.DefaultReactActivityDelegate
import kotlinx.coroutines.launch

class MainActivity : ReactActivity()
{

fun  gotoNext2(){
    this.startActivity<RenderActivity>{
        putExtra("name","name is null")
        putExtra("designPackageId",intent.getStringExtra("designPackageId"))
        putExtra("housePlansDataId",intent.getStringExtra("housePlansDataId"))
        putExtra("housePlansId",intent.getStringExtra("housePlansId"))
    }
}

    fun  gotoNext1(){
        lifecycleScope.launch {
            RetrofitService.instance.addConfigToHouse(accessToken = Robot.accessToken,
                userId = Robot.userId,
                companyId = Robot.companyId,
                housePlanDataId = intent.getStringExtra("housePlansDataId")!!,
                designPackageId = intent.getStringExtra("designPackageId")!!
            )
            gotoHome()
        }
    }

    private fun gotoHome(){
        startActivity<BaseActivity>(){
            intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP)
        }
        finish()
    }

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(null)
    }

  /**
   * Returns the name of the main component registered from JavaScript. This is used to schedule
   * rendering of the component.
   */
  override fun getMainComponentName(): String = "abc"

  /**
   * Returns the instance of the [ReactActivityDelegate]. We use [DefaultReactActivityDelegate]
   * which allows you to enable New Architecture with a single boolean flags [fabricEnabled]
   */
  override fun createReactActivityDelegate(): ReactActivityDelegate =
      DefaultReactActivityDelegate(this, mainComponentName, fabricEnabled)
}
